package com.zt.rongda.companyIncome.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zt.rongda.companyIncome.model.AdWorkBillSettlement;
import com.zt.rongda.companyIncome.service.AdWorkBillSettlementService;
import com.zt.servlet.ReqBean;
import com.zt.servlet.RequestAttribute;
import com.zt.servlet.Response;

import net.sf.json.JSONObject;

@Controller
@RequestMapping(value = "/adWorkBillSettlement")
public class AdWorkBillSettlementController {

    @Autowired
    private AdWorkBillSettlementService adWorkBillSettlementService;

    @RequestMapping(value = "/query")
    @ResponseBody
    
    public JSONObject query(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(adWorkBillSettlementService.getTable(reqBean));
    }

    @RequestMapping(value = "/add")
    @ResponseBody
    
    public JSONObject add(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        adWorkBillSettlementService.add(getAdWorkBillSettlement(reqBean));
        return Response.responseSuccess();
    }

    @RequestMapping(value = "/update")
    @ResponseBody
    
    public JSONObject update(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        adWorkBillSettlementService.update(getAdWorkBillSettlement(reqBean));
        return Response.responseSuccess();
    }

    @RequestMapping(value = "/delete")
    @ResponseBody
    
    public JSONObject delete(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        adWorkBillSettlementService.delete(reqBean.getInfo("settlementId"));
        return Response.responseSuccess();
    }

    /**
    * 从表单获取对象
    *
    * @param reqBean
    * @return
    */
    private AdWorkBillSettlement getAdWorkBillSettlement(ReqBean reqBean) {
        AdWorkBillSettlement adWorkBillSettlement = new AdWorkBillSettlement();
        adWorkBillSettlement.setSettlementId(reqBean.getInfo("settlementId"));
        adWorkBillSettlement.setAdOrderId(reqBean.getInfo("adOrderId"));
        adWorkBillSettlement.setAdContent(reqBean.getInfo("adContent"));
        adWorkBillSettlement.setBusinessType(reqBean.getInfo("businessType"));
        adWorkBillSettlement.setPublishType(reqBean.getInfo("publishType"));
        adWorkBillSettlement.setMakeType(reqBean.getInfo("makeType"));
        adWorkBillSettlement.setCoverAd(reqBean.getInfo("coverAd"));
        adWorkBillSettlement.setAmount(reqBean.getInfoDouble("amount"));
        adWorkBillSettlement.setSettlementDate(reqBean.getInfoDate("settlementDate"));
        adWorkBillSettlement.setOperator(reqBean.getUserId());
        adWorkBillSettlement.setRemark(reqBean.getInfo("remark"));
        return adWorkBillSettlement;
    }

}